//
// Created by Administrator on 2023/2/9.
//

#include <driver/gpio.h>
#include "inc/drv_gpio.h"



void drv_gpio_init(void)
{
    gpio_config_t config[] = {
            {
                .intr_type = GPIO_INTR_DISABLE,
                .mode = GPIO_MODE_OUTPUT,
                .pull_down_en = GPIO_PULLDOWN_DISABLE,
                .pull_up_en = GPIO_PULLUP_DISABLE,
                .pin_bit_mask = (1ull << LCD_BLK) | (1ull << LCD_RST) | (1ull << LCD_TP_RST),
            },
            {
                .intr_type = GPIO_INTR_ANYEDGE,
                .mode = GPIO_MODE_INPUT,
                .pull_down_en = GPIO_PULLDOWN_DISABLE,
                .pull_up_en = GPIO_PULLUP_ENABLE,
                .pin_bit_mask = (1ull << LOCATION_5N31_PPS_PIN) |  (1ull << LCD_PIN_TE),
            },
            #if LCD_SPI_MODE
            {
                    .intr_type = GPIO_INTR_DISABLE,
                    .mode = GPIO_MODE_OUTPUT,
                    .pull_down_en = GPIO_PULLDOWN_DISABLE,
                    .pull_up_en = GPIO_PULLUP_DISABLE,
                    .pin_bit_mask =  (1ull << LCD_QSPI_CS),
            }
            #endif
    };

    for (int i = 0; i < sizeof(config)/sizeof(config[0]); ++i) {
        gpio_config(&config[i]);
    }
    gpio_set_level(GPIO_NUM_2, HIGH);
    gpio_set_level(LOCATION_5N31_PPS_PIN, HIGH);
    gpio_set_level(LCD_RST, HIGH);
    gpio_set_level(LCD_TP_RST, HIGH);
}

void drv_gpio_trigger(gpio_num_t gpio_num)
{
    gpio_set_level(gpio_num, (!gpio_get_level(gpio_num)));
    //ESP_LOGI("drv_gpio_trigger","state: %d", gpio_get_level(gpio_num));
    /*  迷惑行为 上面代码无法进行触发切换 下列代码可以进行闪烁
     *  gpio_set_level(GPIO_NUM_2,HIGH);
        vTaskDelay(1000/portTICK_RATE_MS);
        gpio_set_level(GPIO_NUM_2,LOW);
        vTaskDelay(1000/portTICK_RATE_MS);
        */
}